package thread.threadpool.example2;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description:通过newSingleThreadExecutor获取线程池对象 该方式特点是：只会创建一个线程
 * @date: 2023/1/30 17:30
 * @author: Huangjunjie
 * @since JDK 1.8
 */
public class ExecuTorsTest3 {
    public static void main(String[] args) {
        func1();
    }

    /**
     * 使用 newSingleThreadExecutor 方法得到线程池对象
     */
    private static void func1() {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            //执行线程
            executorService.submit(new MyRunnable(i));
        }
        //销毁线程池（不建议使用）
        executorService.shutdown();
    }
}
